package com.shebao.controller;

import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shebao.service.PersonService;

//个人证明打印接口
@Controller
public class PersonController {
	@Autowired
	private PersonService personService;
	
	@RequestMapping("/findPerson")
	@ResponseBody
	String findPerson(@RequestParam(value="selectType",required=false) Integer selectType,@RequestParam(value="selectCode",required=false) String selectCode){
		return personService.findPerson(selectType, selectCode);
	}
	
	@RequestMapping("/printPerson")
	ResponseEntity<byte[]> printPerson(HttpServletRequest request,HttpServletResponse response,
			@RequestParam(value="selectType",required=false) Integer selectType,@RequestParam(value="selectCode",required=false) String selectCode){	
		HttpHeaders headers = new HttpHeaders(); 
		String fileName = null;  
        try {  
            fileName = new String(("个人-缴费证明-24.pdf").getBytes("gb2312"),"iso-8859-1");//解决中文乱码  
        } catch (UnsupportedEncodingException e) {  
            e.printStackTrace();  
        }//为了解决中文名称乱码问题 
        headers.setContentDispositionFormData("attachment", fileName);     
        headers.setContentType(MediaType.APPLICATION_PDF);   
		return new ResponseEntity<byte[]>(personService.printPerson(selectType, selectCode),headers, HttpStatus.OK); 
	}
}
